package com.openNetty.server.proxy;

import com.openNetty.common.api.BackSqlFile;
import com.openNetty.common.bean.ComRequest;
import com.openNetty.common.bean.ComResponse;
import com.openNetty.common.bean.SendMsgFuture;
import com.openNetty.common.system.LoggerUtil;
import com.openNetty.server.nettyclient.ConnectNode;

/**
 * 代理备份文件下载实现类
 *
 * @version 1.0.0
 * @Author zhenggm
 */
public class BackSqlFileProxy implements BackSqlFile {
    private static LoggerUtil logger = LoggerUtil.getLogger(BackSqlFileProxy.class);
    private ConnectNode connectNode = new ConnectNode();

    @Override
    public ComResponse getSqlBackFile(ComRequest comRequest) {
        return start(comRequest);
    }

    /**
     * 开始请求数据
     *
     * @param comRequest
     * @return
     */
    private ComResponse start(ComRequest comRequest) {
        SendMsgFuture result = connectNode.start(comRequest);

        // 将返回结果进行组装
        ComResponse comResponse = new ComResponse();
        if (result.isSuccess()) {
            comResponse.setResult(result.getMsg());
            logger.debug("任务成功-》》" + result.getMsg());
        } else {
            comResponse.setFilePath(result.getFilepath());
            comResponse.setSuccess(false);
            comResponse.setErrorMsg(result.getMsg());
            logger.debug("任务失败-》》" + result.getMsg());
        }
        return comResponse;
    }
}
